package com.letoken.platform.repo.app.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letoken.platform.repo.admin.req.user.FundCirculationRecordReq;
import com.letoken.platform.repo.app.po.AppFundV2Detail;
import com.letoken.platform.repo.app.po.AppFundV2Info;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 作者
 * @since 2024-02-18
 */
public interface AppFundV2DetailMapper extends BaseMapper<AppFundV2Detail> {




    @Select("select ifnull(sum(amount),0) from app_fund_v2_detail where date(create_time) = #{date} and type != 1")
    BigDecimal sumAmountByDate(LocalDate date);


    @Select("select ifnull(sum(amount),0) from app_fund_v2_detail where type != 1")
    BigDecimal sumAmount();


    @Select("select ifnull(sum(amount),0) from app_fund_v2_detail where date(create_time) = #{date} and type = #{type}")
    BigDecimal sumAmountByDateAndType(@Param("date") LocalDate date, @Param("type") Integer type);


    BigDecimal sumAmountByDateAndTypeAndUserIds(@Param("date") LocalDate date, @Param("type") Integer type, @Param("userIds") List<Integer> userIds);

    BigDecimal sumAmountByTypeAndUserIds(@Param("type") Integer type, @Param("userIds") List<Integer> userIds);


    @Select("select ifnull(sum(amount),0) from app_fund_v2_detail where create_time >= #{startDatetime} and  create_time <= #{endDatetime} and type != 1")
    BigDecimal sumAmountByCreateTime(@Param("startDatetime") LocalDateTime startDatetime, @Param("endDatetime")  LocalDateTime endDatetime);


    @Select("select ifnull(sum(amount),0) from app_fund_v2_detail where create_time >= #{startDatetime} and  create_time <= #{endDatetime} and type = #{type}")
    BigDecimal sumAmountByCreateTimeAndType(@Param("startDatetime") LocalDateTime startDatetime, @Param("endDatetime")  LocalDateTime endDatetime, @Param("type") Integer type);


    Page<AppFundV2Info> page(@Param("page") Page<AppFundV2Info> page, @Param("params") FundCirculationRecordReq params);
}
